Assignment: Build a Search Typeahead System
In this assignment, students will build a search typeahead system similar to the suggestion feature seen in search engines, e-commerce platforms, and content platforms. The system should suggest popular search queries while the user is typing, support search submissions, update query popularity, and use caching to achieve low-latency reads.
The focus of this assignment is the backend data-system design: how query-count data is stored, how suggestions are served quickly, how cache distribution is handled, and how write pressure is reduced.
Build a working search typeahead application with the following capabilities:
1. When a user types in the search box, the system should show 10 suggestions sorted by search count.
2. The application should include a UI interface for searching and displaying suggestions.
3. The backend should expose a dummy search API that returns a response such as "Searched".
4. Whenever a search is submitted, the search-query data store should be updated.
5. Students should design how query-count data is stored and how caching is used for low latency.
6. The cache layer should be distributed using consistent hashing.
7. The system should support trending searches.
8. The system should support batch writes for search-count updates.
Students may use any open-source dataset containing search queries, keywords, product names, page titles, or similar text entries. The dataset should include a count or frequency value for each query. If the chosen dataset does not already include counts, students may derive counts by aggregation.
Expected input format:
query | count |
iphone | 100000 |
iphone 15 | 85000 |
iphone charger | 60000 |
java tutorial | 40000 |
Minimum expected dataset size: 100,000 queries. Larger datasets are encouraged.
Whenever the user types a prefix in the search box, the system should return suggestions matching that prefix.
When the user submits a search, the backend should return a dummy response and update the query-count data.
The following APIs are expected at minimum. Students may add more APIs if required.
API | Purpose | Expected Behavior |
GET /suggest?q=<prefix> | Fetch suggestions | Returns up to 10 prefix-matching suggestions sorted by count. |
POST /search | Submit search | Returns "Searched" and records the submitted query. |
GET /cache/debug?prefix=<prefix> | Debug cache routing | Shows which cache node is responsible for the prefix and whether it is a hit or miss. |
Students must decide how to store search-query data and how to serve suggestions with low latency. They are expected to justify their design choices in the submission and during the viva/mock interview.
The basic version of the typeahead system (for 60% marks) should return suggestions sorted by the overall search count. This means that historically popular queries should appear first.
For the additional 20% marks, students are expected to improve this ranking by incorporating recency. In this version, suggestions should not be sorted only by all-time popularity; instead, recently searched queries should get higher priority.
Students should design a reasonable approach to combine historical popularity and recent activity. The exact scoring formula is left to the students, but they must clearly explain:
The expected behavior is that the same suggestion API should support this improved ranking.
The core API remains:
Basic version:
Enhanced version:
Students should demonstrate the difference between the two ranking approaches using sample data or logs.
Students must support batch writes for search-count updates. The goal is to avoid writing to the primary data store synchronously for every search request.
Use of AI tools is allowed for this assignment. However, students are fully responsible for understanding their submission.
After submission, students are expected to be in a position to explain every major design choice and the core implementation code. This includes data modeling, caching, consistent hashing, trending-search computation, batch-write logic, and important code snippets used in the submitted project.
If a student is unable to explain their design choices or core implementation during a viva/mock interview, the submission may be treated as plagiarism, even if the code runs correctly.
Component | Marks | Expectation |
Basic Implementation | 60 | Working dataset ingestion, search UI, suggestions API, search API, query-count updates, and distributed cache using consistent hashing. |
Trending Searches | 20 | Clear and working trending-search implementation and explanation of the scoring/windowing logic. |
Batch Writes | 20 | Batching or sampling, write-reduction evidence, and discussion of failure trade-offs. |
1. Load dataset and build the basic suggestion API.
2. Build the frontend search box and suggestion dropdown.
3. Add dummy search submission and query-count updates.
4. Add distributed cache with consistent hashing.
5. Add trending searches.
6. Add batch writes.
7. Measure performance and prepare final documentation/demo.
Search Typeahead Assignment